package com.tally.common.enums;

import com.tally.project.system.book.domain.Book;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.apache.commons.compress.utils.Lists;

import java.util.List;

/**
 * @Author soul
 * @Date 2023/5/18 19:31
 * @Description 账本分类
 */
@Getter
@AllArgsConstructor
@NoArgsConstructor
public enum BookEnums {

    BOOK_1("日常", 1001, "red-packet"),
    BOOK_2("宝宝", 1002, "red-packet"),
    BOOK_3("生意", 1003, "red-packet"),
    BOOK_4("结婚", 1004, "red-packet"),
    BOOK_5("投资", 1005, "red-packet"),
    BOOK_6("装修", 1006, "red-packet"),
    BOOK_7("校园", 1007, "red-packet"),
    BOOK_8("旅行", 1008, "red-packet"),
    BOOK_9("人情", 1009, "red-packet"),

    ;
    /** 名称 */
    private String name;
    /** 编号 */
    private int serial;
    /** 图标 */
    private String icon;



    public static Book getBook(int serial) {
        for (BookEnums obj : BookEnums.values()) {
            if (obj.serial == serial){
                return new Book(obj.name, obj.serial, obj.icon);
            }
        }
        return null;
    }

    public static List<Book> toList() {
        // Lists.newArrayList()其实和new ArrayList()几乎一模
        List list = Lists.newArrayList();
        //  一样, 唯一它帮你做的(其实是javac帮你做的), 就是自动推导(不是"倒")尖括号里的数据类型.
        for (BookEnums obj : BookEnums.values()) {
            list.add(new Book(obj.name, obj.serial, obj.icon));
        }
        return list;
    }
}
